home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nannws12.zip / TURNIT.ASM < prev    next >
Assembly Source File  |  1986-09-16  |  4KB  |  116 lines

  1. ;
  2. ;   Title:    TURNIT3.ASM
  3. ;   Author:   F. Ho
  4. ;   Date:     8th July 1986
  5. ;   Syntax:   ? TURN(expC)
  6. ;             where: -expC is the character string expression 
  7. ;                     to be reversed
  8. ;   Note:     - reverses the order of the string passed
  9. ;             - can only process a MAX of 60 characters
  10. ;
  11. public   TURN           ; this public statement makes this
  12. ;                       ; routine accessible to the 'public'
  13. ;
  14. extrn    _PARC:far      ; Clipper's character 'getter'
  15. extrn    _RETC:far      ; Clipper's character 'returner'
  16. ;
  17. ;
  18. DGROUP   GROUP     datasg    ; Clipper's Data Segment
  19.  
  20. ; the 'public' in the next statement combines the datasg
  21. ; to Clipper's DGROUP group
  22. datasg   segment   public    'DATA'
  23.  
  24. RETVAL   db   60   dup(" ")  ; init with 60 spaces
  25. VAL1     dw   00             ; init with 0
  26. VAL2     dw   00             ; init with 0
  27.  
  28. datasg   ends                ; end of datasg (in DGROUP)
  29. ;
  30. ;
  31. _prog    segment
  32.          assume     cs:_prog,ds:DGROUP,es:DGROUP
  33.  
  34. TURN     proc far       ; far process
  35.  
  36.          push bp        ; preserve return address
  37.          mov  bp,sp     ; move stack pointer
  38.         
  39.          mov  ax,1      ; get first para
  40.          push ax        ; push AX
  41.          call _PARC     ; call Chara "getter"
  42.          add  sp,2      ; restore stack
  43.          mov  VAL1,bx   ; get OFFSET address 
  44.          mov  VAL2,ax   ; get SEGMENT address 
  45.     
  46.          push ds        ; preserve DS
  47.          push es        ; preserve ES
  48.          cld            ; clear direction flag (L-R)
  49.          mov  di,offset DGROUP:RETVAL  ; get RETVAL's offset
  50.                                        ; from DGROUP
  51.          mov  ax,DGROUP                ; get DGROUP segment
  52.          mov  es,ax                    ; and place in ES
  53.  
  54. ; in the next three statements, the order that it appears is
  55. ; important because the values of SI & AX must first be taken 
  56. ; from the DATASG extension before assigning the DGROUP segment
  57. ; address to DS
  58.  
  59.          mov  si,VAL1
  60.          mov  ax,VAL2
  61.          mov  ds,ax
  62.                 
  63.     
  64.          xor  ax,ax          ; zero out AX
  65.          mov  al,[si]        ; move first SI value to AL
  66.          cmp  al,0           ; if NUL (zero)
  67.          jz   C3             ; jump to C3
  68.  
  69.          mov  cx,3ch         ; set CX for max 60 loops
  70.          xor  bx,bx          ; zero-out BX
  71.          xor  ax,ax          ; zero-out AX
  72.  
  73. A1:      mov  al,[si]        ; move SI value to AL
  74.          cmp  al,0           ; compare with zero
  75.          jz   A2             ; if zero, jump to A2:
  76.          inc  si             ; increment SI
  77.          inc  bx             ; increment BX
  78.          loop A1             ; loop to A1:
  79.  
  80. A2:      dec  si             ; decrement SI
  81.          mov  cx,bx          ; move BX to CX
  82.          xor  ax,ax          ; zero-out AX
  83.  
  84. A3:      mov  al,[si]        ; move    SI val to AL
  85.          mov  es:[di],al     ; move    AL to DI
  86.          dec  si             ; decrement SI
  87.          inc  di             ; increment DI
  88.          loop A3             ; loop
  89.     
  90. C3:      xor  ax,ax          ; zero-out AX
  91.          mov  es:[di],al     ; add null terminator to end
  92.                              ; of RETVAL
  93.  
  94.          pop  es             ; restore
  95.          pop  ds             ; restore
  96.  
  97.          pop  bp             ; restore
  98.  
  99.          mov  ax,DGROUP      ; get DGROUP address
  100.          mov  ds,ax          ; assign to DS
  101.          push ds             ; push segment address
  102.  
  103.          mov  ax,offset DGROUP:RETVAL  ; get RETVAL's offset
  104.          push ax             ; push offset address
  105.          call _RETC          ; Clipper's  "returner"
  106.          pop  ax             ; restore
  107.          pop  ds             ; restore
  108.  
  109.          ret                 ; actual ret to caller
  110. TURN     endp                ; end of process
  111.  
  112. _prog    ends                ; end of segment
  113.          end                 ; end of programme
  114. ;
  115. ;
  116.